Dialog = function(options){
	var _options = {};
	$.extend(_options,this._options,options);
	$.extend(this,{
		_options:_options
	});
	this._init();
};
Dialog.prototype= {
	_options:{
		width:600,
		height:300
	},
	_mask:null,
	_timing:null,
	//----------------------------------------------------------------------------------------------//初始化
	_init:function(){
		this._mask = new Mask({
			target:window.top.document.body
		});
	},
	//----------------------------------------------------------------------------------------------//弹出提示框
	alert:function(msg,detailMsg,confirmCallback,closeCallback){
		var modal = document.createElement("div");
		modal.setAttribute("class", "xl-dialog alert warning");
		
		var titleElement = document.createElement("h1");
		titleElement.setAttribute("class", "xl-dialog-title");

		var titleIcon = document.createElement("i");
		titleIcon.setAttribute("class", "fa fa-th");
		
		var titleToolbar = document.createElement("span");
		titleToolbar.setAttribute("class", "xl-dialog-title-toolbar");
		
		var toolbarItem = document.createElement("a");
		toolbarItem.setAttribute("href", "javascript:void 0;");

		var toolbarItemIcon = document.createElement("i");
		toolbarItemIcon.setAttribute("class", "fa fa-times");
		
		var contentElement = document.createElement("div");
		contentElement.setAttribute("class", "xl-dialog-content");

		var tipsIcon = document.createElement("i");
		tipsIcon.setAttribute("class", "fa fa-exclamation-circle  xl-dialog-icon");

		var message = document.createElement("p");
		message.setAttribute("class", "xl-dialog-message");

		var detailMessage = document.createElement("p");
		detailMessage.setAttribute("class", "xl-dialog-message detail");
		
		var buttons = document.createElement("div");
		buttons.setAttribute("class", "xl-dialog-buttons clear");

		var confirmButton = document.createElement("button");
		confirmButton.setAttribute("type", "button");
		confirmButton.setAttribute("class", "btn btn-sm");
		confirmButton.appendChild(document.createTextNode("确定"));
		
		buttons.appendChild(confirmButton);
		
		toolbarItem.appendChild(toolbarItemIcon);
		titleToolbar.appendChild(toolbarItem);
		
		titleElement.appendChild(titleIcon);
		titleElement.appendChild(document.createTextNode(" 操作提示"));
		titleElement.appendChild(titleToolbar);

		message.appendChild(document.createTextNode(msg));
		detailMessage.appendChild(document.createTextNode(detailMsg));
		
		contentElement.appendChild(tipsIcon);
		contentElement.appendChild(message);
		contentElement.appendChild(detailMessage);
		
		modal.appendChild(titleElement);
		modal.appendChild(contentElement);
		modal.appendChild(buttons);

		modal.style.width = Utils.pixel.style(500);
		modal.style.height = Utils.pixel.style(245);

		$(toolbarItem).click($.proxy(this._close(closeCallback),this));
		$(confirmButton).click($.proxy(this._confirm(confirmCallback),this));
		
		this._mask.open(modal);
	},
	//----------------------------------------------------------------------------------------------//弹出确认框
	confirm:function(msg,confirmCallback,cancelCallback,closeCallback){
		var modal = document.createElement("div");
		modal.setAttribute("class", "xl-dialog confirm info");
		
		var titleElement = document.createElement("h1");
		titleElement.setAttribute("class", "xl-dialog-title");

		var titleIcon = document.createElement("i");
		titleIcon.setAttribute("class", "fa fa-th");
		
		var titleToolbar = document.createElement("span");
		titleToolbar.setAttribute("class", "xl-dialog-title-toolbar");
		
		var toolbarItem = document.createElement("a");
		toolbarItem.setAttribute("href", "javascript:void 0;");

		var toolbarItemIcon = document.createElement("i");
		toolbarItemIcon.setAttribute("class", "fa fa-times");
		
		var contentElement = document.createElement("div");
		contentElement.setAttribute("class", "xl-dialog-content");

		var tipsIcon = document.createElement("i");
		tipsIcon.setAttribute("class", "fa fa-question-circle  xl-dialog-icon");

		var message = document.createElement("p");
		message.setAttribute("class", "xl-dialog-message");

		var detailMessage = document.createElement("p");
		detailMessage.setAttribute("class", "xl-dialog-message detail");
		
		var buttons = document.createElement("div");
		buttons.setAttribute("class", "xl-dialog-buttons clear");

		var confirmButton = document.createElement("button");
		confirmButton.setAttribute("type", "button");
		confirmButton.setAttribute("class", "btn btn-sm");
		confirmButton.appendChild(document.createTextNode("确定"));
		
		var cancelButton = document.createElement("button");
		cancelButton.setAttribute("type", "button");
		cancelButton.setAttribute("class", "btn btn-sm");
		cancelButton.appendChild(document.createTextNode("取消"));

		buttons.appendChild(confirmButton);
		buttons.appendChild(document.createTextNode("      "));
		buttons.appendChild(cancelButton);
		
		toolbarItem.appendChild(toolbarItemIcon);
		titleToolbar.appendChild(toolbarItem);
		
		titleElement.appendChild(titleIcon);
		titleElement.appendChild(document.createTextNode(" 操作提示"));
		titleElement.appendChild(titleToolbar);

		message.appendChild(document.createTextNode(msg));
		detailMessage.appendChild(document.createTextNode("确定，继续进行数据操作，取消，当前操作将取消。 "));
		
		contentElement.appendChild(tipsIcon);
		contentElement.appendChild(message);
		contentElement.appendChild(detailMessage);
		
		modal.appendChild(titleElement);
		modal.appendChild(contentElement);
		modal.appendChild(buttons);

		modal.style.width = Utils.pixel.style(500);
		modal.style.height = Utils.pixel.style(245);

		$(toolbarItem).click($.proxy(this._close(closeCallback),this));
		$(cancelButton).click($.proxy(this._cancel(cancelCallback),this));
		$(confirmButton).click($.proxy(this._confirm(confirmCallback),this));
		
		this._mask.open(modal);
	},
	error:function(message,closeCallback){
		var modal = this._createModal("error","fa-times-circle","操作失败",message,"页面将在{s}秒后自动跳转！",closeCallback);
		this._mask.open(modal);
	},
	success:function(message,closeCallback){
		var modal = this._createModal("success","fa-check-circle","操作成功",message,"页面将在{s}秒后自动跳转！",closeCallback);
		this._mask.open(modal);
		
	},
	_createModal:function(category,icon,msg,detailMsg,operationMsg,callback){
		var second = 2;
		var modal = document.createElement("div");
		modal.setAttribute("class", "xl-dialog "+category);
		
		var titleElement = document.createElement("h1");
		titleElement.setAttribute("class", "xl-dialog-title");

		var titleIcon = document.createElement("i");
		titleIcon.setAttribute("class", "fa fa-th");
		
		var titleToolbar = document.createElement("span");
		titleToolbar.setAttribute("class", "xl-dialog-title-toolbar");
		
		var toolbarItem = document.createElement("a");
		toolbarItem.setAttribute("href", "javascript:void 0;");

		var toolbarItemIcon = document.createElement("i");
		toolbarItemIcon.setAttribute("class", "fa fa-times");
		
		var contentElement = document.createElement("div");
		contentElement.setAttribute("class", "xl-dialog-content");

		var tipsIcon = document.createElement("i");
		tipsIcon.setAttribute("class", "fa "+icon+"  xl-dialog-icon");

		var message = document.createElement("p");
		message.setAttribute("class", "xl-dialog-message");

		var detailMessage = document.createElement("p");
		detailMessage.setAttribute("class", "xl-dialog-message detail");
		
		var operationMessage = document.createElement("p");
		operationMessage.setAttribute("class", "xl-dialog-message operation");
		
		toolbarItem.appendChild(toolbarItemIcon);
		titleToolbar.appendChild(toolbarItem);
		
		titleElement.appendChild(titleIcon);
		titleElement.appendChild(document.createTextNode(" 操作提示"));
		titleElement.appendChild(titleToolbar);

		message.appendChild(document.createTextNode(msg));
		detailMessage.appendChild(document.createTextNode(detailMsg));
		operationMessage.appendChild(document.createTextNode(operationMsg.replace("{s}",second)));
		
		contentElement.appendChild(tipsIcon);
		contentElement.appendChild(message);
		contentElement.appendChild(detailMessage);
		contentElement.appendChild(operationMessage);
		
		modal.appendChild(titleElement);
		modal.appendChild(contentElement);


		modal.style.width = Utils.pixel.style(500);
		modal.style.height = Utils.pixel.style(250);
	
		$(toolbarItem).click($.proxy(this._close(callback),this));
		
		//延迟跳转
		this._timing = new Timing({
			maxms:second*1000,
			minms:0,
			callback:$.proxy(function(remain){
				if(remain.second==0){
					$.proxy(this._close(callback),this)();
				}else{
					var text = operationMsg.replace("{s}",remain.second);
					$(operationMessage).text(text);
				}
			},this)
		});
		this._timing.start();
		this._mask.close($.proxy(function(){
			this._timing.stop();
		},this));
		
		return modal;
	},
	//----------------------------------------------------------------------------------------------//弹出对话框
	iframe:function(option){
		var _option = $.extend({
			url:"#",
			width:window.top.document.body.offsetWidth -200,
			height:window.top.document.body.offsetHeight -40
		},option);
		var iframe = document.createElement("iframe");
		iframe.setAttribute("frameborder","0");
		iframe.setAttribute("class","xl-module");
		iframe.setAttribute("src",_option.url);
		iframe.style.width = Utils.pixel.style(_option.width);
		iframe.style.height = Utils.pixel.style(_option.height);
		
		this._mask.open(iframe,true);
	},
	div:function(){
		
	},
	_close:function(callback){
		return function(){
			if(callback && typeof(callback)=="function"){
				callback();
			}
			this._mask.close();
		};
	},
	_cancel:function(callback){
		return function(){
			if(callback && typeof(callback)=="function"){
				callback();
			}
			this._mask.close();
		};
	},
	_confirm:function(callback){
		return function(){
			if(callback && typeof(callback)=="function"){
				callback();
			}
			this._mask.close();
		};
	}
};